package com.itheima.tlias.service.impl;

import com.itheima.tlias.mapper.EmpMapper;
import com.itheima.tlias.mapper.StudentMapper;
import com.itheima.tlias.service.ReportService;
import com.itheima.tlias.service.StudentService;
import com.itheima.tlias.vo.EmpJobDataVo;
import com.itheima.tlias.vo.NameValueVo;
import com.itheima.tlias.vo.StudentClazzDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public EmpJobDataVo empJobData() {
        List<NameValueVo> voList = empMapper.empJobData();
        if (CollectionUtils.isEmpty(voList)) {
            return new EmpJobDataVo();
        }
        List<String> jobList = voList.stream().map(NameValueVo::getName).collect(Collectors.toList());
        List<Integer> dataList = voList.stream().map(NameValueVo::getValue).collect(Collectors.toList());
        return new EmpJobDataVo(jobList, dataList);
    }

    @Override
    public List<NameValueVo> empGenderData() {
        return empMapper.empGenderData();
    }

    @Override
    public List<NameValueVo> studentDegreeData() {
        List<NameValueVo> nameValueVos = studentMapper.studentDegreeData();
        return nameValueVos;
    }

    @Override
    public StudentClazzDataVo studentCountData() {
        List<NameValueVo> voList = studentMapper.studentCountData();
        if (CollectionUtils.isEmpty(voList)) {
            return new StudentClazzDataVo();
        }
        List<String> name = voList.stream().map(NameValueVo::getName).collect(Collectors.toList());
        List<Integer> value = voList.stream().map(NameValueVo::getValue).collect(Collectors.toList());
        return new StudentClazzDataVo(name,value);
    }
}
